package TUILayer;
import ControlLayer.*;
import java.util.Scanner;

/**
 * Write a description of class LoanUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanUI
{
    // instance variables - replace the example below with your own
    private LoanCtr loanCtr;


    /**
     * Constructor for objects of class LoanUI
     */
    public LoanUI()
    {
        loanCtr = new LoanCtr();
   
    }
    
    public void start()
    {
        loanMenu();
        
    }
    
    public void loanMenu()
    {
        boolean exit = false;
        while(!exit)
        {
            //Show menu and return the users choice
            int choice = writeLoanMenu();
            if (choice == 1)
            {
                showLoan();
            }
            else{if(choice == 2){
                addLoan();
            }
            else{if(choice == 3){
                returnLoan();
            }
            else{if(choice == 4){
                showAllLoans();
            }
            else{
                exit = true;
            }
            }//end else
            }//end else
            }//end else
        }
    }//end while
    
    public int writeLoanMenu()
    {
         // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Loan Menu ***");
            System.out.println(" (1) Show Loan information");
            System.out.println(" (2) Create Loan ");
            System.out.println(" (3) return Loan");
            System.out.println(" (4) Show current Loan list");
            System.out.println(" (5) Exit ");
            System.out.print("\n Make your choice: ");
            
            int choice = keyboard.nextInt();
            return choice;
    }
    private String inputPhone()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please write the phone number of the person");
        String p = keyboard.nextLine();
        return p;
    }
    private String inputID()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please write the id of the dvd");
        String i = keyboard.nextLine();
        return i;
    }
    private String inputLoanDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please write the date the loan is started");
        String ld = keyboard.nextLine();
        return ld;
    }
    private String inputReturnDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please write the date the loan is to be returned");
        String rd = keyboard.nextLine();
        return rd;
    }
    private String inputCopyNr()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please write the copy number");
        String cr = keyboard.nextLine();
        return cr;
    }
    
    public void addLoan()
    {
        String phone = inputPhone();
        String id = inputID();
        String copyNr = inputCopyNr();
        String loanDate = inputLoanDate();
        String returnDate = inputReturnDate(); 
        loanCtr.addLoan(phone, id, copyNr, loanDate, returnDate);
        waitInput();    
 
    }
    
    public void returnLoan()
    {
        String phone = inputPhone();
        loanCtr.deleteLoan(phone);
        waitInput();
    }
    
    public void showAllLoans()
    {
        loanCtr.printAllLoans();
        waitInput();
    }
    
    public void showLoan()
    {
        String phone = inputPhone();
        loanCtr.findLoan(phone);
        waitInput();
    }
    
    private void waitInput()
    {
        System.out.println("Press enter to continue");
        new Scanner(System.in).nextLine();
    }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

